<?php
if (!defined('IN_XLP')) {
    exit('Access Denied');
}
?>
<!--主体 开始-->
    <div class="row" style="width:500px">
      <div class="col-sm-12">
        <section class="panel">
          <div class="panel-body">
            <form class="form-horizontal" method="post" id="form1">
                <div class="form-group"> 
                  <label class="col-sm-3 control-label">头图设置</label>    
                  <div class="col-sm-8"> 
                       <!---->
                        <div class="cover-area">
                              <div class="cover-hd">
                                <input id="file_upload" name="file_upload" type="file" />
                                <input id="coverurl" value="<?php echo $coverurl;?>" name="coverurl" type="hidden" /> 
                               </div>
                              
                              <p id="imgArea" class="cover-bd" <?php  if(!$coverurl){ echo 'style="display: none;"';   } ?>><img src="<?php echo getImgUrl($coverurl);?>" id="img">
                                  <a href="javascript:;" class="vb cover-del" style=" float:right;" id="delImg">删除</a>
                              </p>
                        </div>
                        <!---->
                     <br class="clear" />   
                  </div>
             	</div>
              <div class="form-group">
                  <div class="col-sm-9 col-lg-offset-1">
                    <div class="col-sm-4"><button type="submit" id="sub-ok" class="btn btn-primary">保存</button></div>
                    <div class="col-md-offset-2"><button type="button" id="close-btn" class="btn btn-white">关闭</button></div>
                  </div>
               </div>
            </form>
          </div>
        </section>
      </div>
    </div>
<!--主体 结束-->
<script src="/statics/default/js/content/operamasks-ui.min.js"></script>
<script>
var UEDITOR_HOME_URL = '/statics/default/ueditor/';
var postPicUrl='<?php echo U("nearby/postpic"); ?>';
var uplodePicUrl='<?php echo U("nearby/cover_post"); ?>';
$(function(){
	    $("#file_upload").omFileUpload({
	        action: postPicUrl,
	        fileExt: "*.jpg;*.png;*.gif;*.jpeg;*.bmp",
	        fileDesc: "Image Files",
	        sizeLimit: 2 * 1024 * 1024,
	        onError: function(ID, fileObj, errorObj, event) {
	            if (errorObj.type == "File Size") {
	                Msg.error("上传图片的大小不能超过2M")
	            }
	        },
	        autoUpload: true,
	        swf: UEDITOR_HOME_URL+"swf/om-fileupload.swf",
	        method: "POST",
	        actionData: {},
	        onComplete: function(ID, fileObj, response, data, event) {
	            var jsonData = eval("(" + response + ")");
	            if (jsonData.result == "error") {
	                Msg.error(jsonData.msg);
	                return false
	            }
	            $(".cover .i-img").attr("src", jsonData.fileUrl).show();
	            $("#imgArea").show().find("#img").attr("src", jsonData.fileUrl);
	            $("#coverurl").val(jsonData.savePath);
	            $(".default-tip").hide()
	        }
	    });
	    $("#delImg").click(function() {
	        $("#isCover").attr("checked",false);
	        $(".default-tip").show();
	        $("#imgArea").hide();
	        $("#coverurl").val("");
	        $(".cover .i-img").hide()
	    });
	$("#close-btn").click(function(){
		$(document).trigger('close.facebox')
	})
	$('#form1').submit(function(){
		if (!$('#coverurl').val()){
			Msg.error('请上传图片');
			resetSubmit("#sub-ok",'保存');
			return false;
		}
		Msg.loading();
		  $.post(uplodePicUrl,$(this).serialize(),function(result){
			  Msg.hide();
			  resetSubmit("#sub-ok",'保存');
			  if (result.status==1){
				Msg.ok('添加成功',function(){
					document.location.reload();	
				},1000);
			}else{
				Msg.error(result.info);
			}
		  },'json');
		  return false;
	})	
})
</script>
